/**
 * 行政老师添加年度
 * 
 * /xingzheng/year/add
 */


const Year = require('../../../models/years')
const utils = require('../../../utils/index')
const $ = require('../../../utils/common')

const add = async function (req, res) {
    try {
        // 参数检查
        delete req.body.id

        if (!req.body.dead_line) {
            $.sendMessage(res, 1015, '参数dead_line没有传')
            return
        }

        if (!req.body.type) {
            $.sendMessage(res, 1015, '参数type没有传')
            return
        }

        if (!req.body.name) {
            $.sendMessage(res, 1015, '参数name没有传')
            return
        }

        var result = await Year.create(req.body)

        res.json({
            code: 200,
            message: '添加成功',
            result: result
        })
            
        // 日志
        utils.create_a_log(req, '年度管理', '添加')
    }
    catch(error) {
        $.log('catch error :', error)
        res.json({
            message: "抓到异常",
            error: 'error' + error
        })
        utils.create_a_log(req, '年度管理', '添加', '失败')
    } 
}
    
module.exports = add